<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/11/24
 * Time: 15:51
 */

namespace App\Plugin\HostServer\Admin;



use App\Plugin\HostServer\Models\PnHostSvCategory;
use App\Plugin\HostServer\Models\PnHostSvGood;
use App\Plugin\HostServer\Models\PnHostSvSearch;
use App\Plugin\HostServer\Models\PnHostSvSystemGoods;
use Illuminate\Http\Request;

class SearchController extends BaseController
{

    public function indexData()
    {
        $item =PnHostSvSearch::all();
        return $item;
    }


    public function setModel()
    {
        $this->model= new PnHostSvSearch();
    }



    /**
     * 系统添加
     * @param $data
     * @param $goods_id
     * @return array|bool
     */

    public function createEditData($show = '')
    {
        $list_key=array_values($this->searchData());
        return [
            'list'=>$list_key
        ];
    }

    /**
     * 创建者:蒙牛、阿磊
     * 创建时间:2019/12/6 15:18
     * 函数说明:重写父类的模型保存函数
     * 调用方式: post
     * @param Request $request
     * @return array|\Illuminate\Http\JsonResponse
     */
    public function store(Request $request)
    {
        $model = $this->getModel();
        $item_key=$request->input('item_key');
        $arr=$this->searchData();
        $item_value=array_search($item_key,$arr);
        $request->offsetSet('item_key',$item_key);
        $request->offsetSet('item_value',$item_value);
        return $this->saveData($request, $model);
    }

    /**
     * 创建者:蒙牛、阿磊
     * 创建时间:2019/12/6 15:18
     * 函数说明:搜索词典，暂时以这样的方式存在
     * 调用方式:get
     * @return array
     */
    public function searchData()
    {
        $list_key=[
            'area'=>'所在地区',
            'money'=>'价格',
            'memory'=>'内存',
            'cpu'=>'CPU核数',
            'name'=>'名称',
            'bandwidth'=>'带宽',
            'feature'=>'特点',
            'disk'=>'硬盘大小',
            'disk_type'=>'硬盘类型',
            'support_system'=>'系统类型',
            'money_sort'=>'价格排序',
        ];
        return $list_key;
    }
}
